package io.sage.modules.basics.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import io.sage.modules.basics.dao.BGoodsAllocationMapper;
import io.sage.modules.basics.entity.BGoodsAllocation;
import io.sage.modules.basics.service.BGoodsAllocationService;

@Service("goodsAllocationService")
public class BGoodsAllocationServiceImpl implements BGoodsAllocationService {
	
	@Autowired
	private BGoodsAllocationMapper goodsAllocationMapper;
	
	
	@Override
	public List<BGoodsAllocation> selectGoodsAllocationList(Map<String, Object> params) {

		return goodsAllocationMapper.selectGoodsAllocationList(params);
	}


	@Override
	public BGoodsAllocation selectByPrimaryKey(Integer id) {

		return goodsAllocationMapper.selectByPrimaryKey(id);
	}


	@Override
	public int insert(BGoodsAllocation goodsAllocation) {
		goodsAllocation.setCreateTime(new Date());
		goodsAllocation.setUpdateTime(new Date());
		goodsAllocation.setIsDel(0);
		goodsAllocation.setIsUsed(1);
		return goodsAllocationMapper.insertSelective(goodsAllocation);
	}


	@Override
	public int updateByPrimaryKeySelective(BGoodsAllocation goodsAllocation) {
		goodsAllocation.setUpdateTime(new Date());
		int i=goodsAllocationMapper.updateByPrimaryKeySelective(goodsAllocation);
		if(i>0){
			goodsAllocationMapper.updateIsUsedById(goodsAllocation.getId());
		}
		return i;
	}


	@Override
	public int deleteBatchIds(Integer[] ids) {
		return goodsAllocationMapper.deleteBatchIds(ids);
	}

}
